<template>
  <view>
    <u-popup :show="show" @close="close" mode="bottom" round="28rpx">
      <view class="popup-content">
        <ProvincesScreen
          :showAllOption="false"
          :list="areaData"
          :checkIds="areaCheckIds"
          @changeCheck="areaChangeCheck"
        />
      </view>
      <view class="popup-footer">
        <!-- <view class="popup-footer-item">
          <text>取消</text>
        </view> -->
        <view class="popup-footer-item" @click="onSubmit">
          <text>确定</text>
        </view>
      </view>
    </u-popup>
  </view>
</template>
<script>
import ProvincesScreen from "@/components/ProvincesScreen.vue";
import { provincesListApi } from "@/services/common";
export default {
  components: {
    ProvincesScreen,
  },
  data() {
    return {
      areaData: [],
      areaCheckIds: [],
      show: false,
      areaNames: [],
    };
  },
  mounted() {
    provincesListApi().then((res) => {
      this.areaData = res.data?.area_list || [];
    });
  },
  methods: {
    open() {
      this.show = true;
    },
    close() {
      this.show = false;
    },
    areaChangeCheck(e, names) {
      this.areaCheckIds = e;
      this.areaNames = names;
    },
    onSubmit() {
      if (this.areaCheckIds.some((item) => !item)) return;
      this.$emit("onSubmit", this.areaCheckIds, this.areaNames);
      this.close();
    },
  },
};
</script>
<style lang="scss" scoped>
.popup-content {
  padding: 20rpx;
}

.popup-footer {
  display: flex;
  justify-content: space-between;
  padding: 20rpx;
}

.popup-footer-item {
  width: 100%;
  height: 80rpx;
  background-color: #f00;
  border-radius: 10rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 32rpx;
  color: #fff;
}
</style>
